﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DZPK.SocketImpl
{
    public class RoomsocketSend
    {
        const int SERVER_COMMAND_MTTSNGCHANGETABLE = 16442;
        const int SERVER_COMMAND_VOTEKICKUSER = 16416;
        const int CLIENT_COMMAND_MTTSNGRANKDATA = 4115;
        const int SERVER_COMMAND_USER_FROMTOALLCHIPS = 16406;
        const int SERVER_COMMAND_USER_NOTICEALL = 16407;
        const int SERVER_COMMAND_SNGALLLOGIN_SUCCESS = 16429;
        const int SERVER_DETECT_CONN = 28673;
        const int SERVER_COMMAND_USERLOGIN = 16431;
        const int SERVER_COMMAND_DEAL_RIVER = 16397;
        const int SERVER_COMMAND_MTTSNGUSEROVERINFO = 16441;
        const int CLIENT_COMMAND_CONNECTSUCCEED = 0x0101;
        const int CLIENT_COMMAND_USER_FROMTOALLCHIPS = 4104;
        const int SERVER_SUBPACKET_VER2 = 2;
        const int SERVER_COMMAND_START_CHIPIN = 16398;
        const int CLIENT_COMMAND_LOTTERYBUY = 4113;
        const int SERVER_COMMAND_USERLOGOUT = 16432;
        const int CLIENT_COMMAND_UPDATE_USER_INFO = 4117;
        const int SERVER_COMMAND_VENUECOSTS = 16422;
        const int SERVER_COMMAND_FINAL_GAME = 16401;
        const int SERVER_COMMAND_USER_CHANGE_SERVER = 20481;
        const int SERVER_COMMAND_DEAL_PREFLOP = 16394;
        const int SERVER_COMMAND_STANDTIMING = 0x4040;
        const int CLIENT_CMD_CONNECT_GAMESERVER_S = 8193;
        const int SERVER_COMMAND_SHOWDEALPREFLOPCARD = 16438;
        const int CLIENT_COMMAND_USER_KICKUSER_REQUEST = 4110;
        const int SERVER_COMMAND_TABLECHATHISTORY = 16409;
        const int SERVER_PACKET_VER = 2;
        const int SERVER_COMMAND_STOPSERVER = 16420;
        const int CLIENT_COMMAND_CONNECTFAILED = 258;
        const int SERVER_COMMAND_MTTFINAL = 16445;
        const int CLIENT_COMMAND_CHANGE_SERVER_USER_LOGIN = 4118;
        const int CLIENT_COMMAND_SNGTABLEINFO = 0x1010;
        const int SERVER_COMMAND_SYSTOOTHER = 16412;
        const int CLIENT_COMMAND_SHOWDEALPREFLOPCARD = 4114;
        const int CLIENT_COMMAND_SIT_REQUEST = 4099;
        const int SERVER_COMMAND_SNGTIMESMALLBLIN = 16433;
        const int SERVER_COMMAND_GLODRUSHCHANGEROOM = 16446;
        const int CLIENT_CMD_CONNECT_GAMESERVER = 2049;
        const int SERVER_COMMAND_USER_FROMTOCHIPS = 16405;
        const int SERVER_COMMAND_USER_ADDFRIEND_SUCCESS = 16415;
        const int SERVER_BROADCAST_USER_SIT = 16390;
        const int SERVER_COMMAND_LOTTERYBUY = 16434;
        const int SERVER_COMMAND_SYSKICKUSER = 16436;
        const int CLIENT_COMMAND_USER_NOTICEALL = 4105;
        const int SERVER_COMMAND_RANK_ONE_NOTICE = 16451;
        const int SERVER_COMMAND_SIT_FAILED = 16389;
        const int SERVER_CMD_CONNECT_GAMESERVER_FAILED = 2306;
        const int SERVER_COMMAND_USER_ADDFRIEND = 16414;
        const int SERVER_COMMAND_CHANGESERVER = 16444;
        const int CLIENT_COMMAND_TABLEINFO_REQUEST = 4100;
        const int SERVER_COMMAND_USER_ACTION = 16399;
        const int SERVER_COMMAND_SNGBIND_SUCCESS = 16424;
        const int SERVER_COMMAND_SNGALLBIND_SUCCESS = 16430;
        const int SERVER_COMMAND_LOTTERYMONEY = 16435;
        const int SERVER_COMMAND_USER_NOT_FOUND = 16385;
        const int SERVER_COMMAND_VOTEEND = 16418;
        const int SERVER_BROADCAST_GAME_START = 16393;
        const int SERVER_COMMAND_KICKUSER_RESPONSE = 16419;
        const int SERVER_COMMAND_USER_SMALLFEES = 16421;
        const int CLIENT_COMMAND_LOGIN = 4097;
        const int CLIENT_COMMAND_ROOMINFO_REQUEST = 4119;
        const int SERVER_CMD_CONNECT_GAMESERVER_SUCCESS_S = 8194;
        const int SERVER_COMMAND_TABLEINFO_RESPONSE = 16392;
        const int SERVER_COMMAND_MTTSNGUSERRANKINFO = 16440;
        const int CLIENT_COMMAND_CONNECTCLOSE = 259;
        const int SERVER_BROADCAST_SNGGAME_START = 16425;
        const int CLIENT_COMMAND_LOGOUT = 4098;
        const int SERVER_BROADCAST_USER_STAND = 16391;
        const int SERVER_COMMAND_USER_KICK = 16408;
        const int SERVER_COMMAND_SNGUSERSTANDINFO = 16426;
        const int CONBROKEN_INTERVAL = 10;
        const int CLIENT_COMMAND_USER_VOTEKICKUSER = 4109;
        const int SERVER_AND_CLIENT_MAX_COMMAND = 16449;
        const int CLIENT_COMMAND_USER_STAND = 4106;
        const int SERVER_COMMAND_SNGUSERRANKINFO = 16428;
        const int SERVER_COMMAND_LOGINOUT_SUCCESS = 16413;
        const int SERVER_USERCHIPIN_ERR = 12289;
        const int CLIENT_COMMAND_CHIPIN = 4101;
        const int CLIENT_COMMAND_USER_ADDFRIEND_SUCCESS = 4108;
        const int CLIENT_COMMAND_CONTINUE = 4116;
        const int SERVER_COMMAND_USER_CHAT = 16403;
        const int SERVER_COMMAND_LOGIN_ERR = 16386;
        const int DETECT_CONN_TIME = 30;
        const int SERVER_SUBPACKET_VER = 1;
        const int CLIENT_COMMAND_USER_ADDFRIEND = 4107;
        const int SERVER_COMMAND_PACKETVERERR = 12290;
        const int SERVER_COMMAND_MTTSNGRANKDATA = 16439;
        const int CLIENT_ECHO_CONN = 28674;
        const int SERVER_COMMAND_USERUPDATAEXP = 16437;
        const int SERVER_COMMAND_SYSMSG = 16410;
        const int SERVER_COMMAND_SNGTALBESTATE = 16427;
        const int SERVER_COMMAND_BIND_SUCCESS = 16404;
        const int CLIENT_COMMAND_USER_SMALLFEES = 4111;
        const int SERVER_COMMAND_USER_KICKUSER_RESPONSE = 16417;
        const int SERVER_COMMAND_DEAL_TURN = 16396;
        const int SERVER_CMD_CONNECT_GAMESERVER_FAILED_S = 8195;
        const int SERVER_COMMAND_LOGIN_SUCCESS = 16387;
        const int SERVER_COMMAND_SHOW_PREFLOP = 16402;
        const int SERVER_COMMAND_DEAL_FLOP = 16395;
        const int CLIENT_COMMAND_USER_FROMTOCHIPS = 4103;
        const int SERVER_COMMAND_SNGLOGIN_SUCCESS = 16423;
        const int SERVER_COMMAND_FINAL_ROUND = 16400;
        const int SERVER_COMMAND_SIT_SUCCESS = 16388;
        const int SERVER_CMD_CONNECT_GAMESERVER_SUCCESS = 2305;
        const int SERVER_COMMAND_MTTSNGTIMESTART = 16443;
        const int CLIENT_COMMAND_USER_CHAT = 4102;
        const int SERVER_COMMAND_SYSTOUSERCHIPS = 16411;

        private TcpSocket _mySokcet = null;

        public RoomsocketSend(TcpSocket socket)
        {
            _mySokcet = socket;
        }

        public void RequestAddFriendSuccess(int _arg1, int _arg2, int _arg3, int _arg4)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_ADDFRIEND_SUCCESS, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeByte(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeInt(_arg4);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void stopLittleTime()
        {
            //_clientSocket.stopLittleTimer();
            throw new NotImplementedException();
        }

        public void RequestMttSngRankData(int _arg1, int _arg2)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_MTTSNGRANKDATA, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public bool connected()
        {
            return _mySokcet.getConnecState();
        }

        public void SetLittleEndian()
        {
            _mySokcet.setLittleEndian();
        }

        public void init()
        {
            //_gameProcess = _arg1;
            //_processCmd = new ProcessCMD(_gameProcess);
            //_clientSocket = new ClientSocket(_processCmd);
            _mySokcet = new TcpSocket(null);
        }

        public void SetBigEndian()
        {
            _mySokcet.setBigEndian();
        }

        public void SendUserInfosUpdate()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_UPDATE_USER_INFO, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void SendConnectGameServer(string _arg1, int _arg2)
        {
            _mySokcet.writeErlBegin(CLIENT_CMD_CONNECT_GAMESERVER_S, 2, 1);
            _mySokcet.writeString(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeErlEnd();
            _mySokcet.sendErlCmd();
        }

        public void RequestSngTableInfo()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_SNGTABLEINFO, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void SendLogin(int _arg1, int _arg2, string _arg3, string _arg4, string _arg5, string _arg6, string _arg7, string _arg8)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_LOGIN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeString(_arg3);
            _mySokcet.writeString(_arg4);
            _mySokcet.writeString(_arg5);
            _mySokcet.writeString(_arg6);
            _mySokcet.writeString(_arg7);
            _mySokcet.writeString(_arg8);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void SendRequestRoomInfo()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_ROOMINFO_REQUEST, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestUserStand()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_STAND, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestSmallFees(int _arg1)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_SMALLFEES, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestUserVoteKickUser(int _arg1, int _arg2, int _arg3)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_VOTEKICKUSER, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeByte(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestChangeSeverLogin(int _arg1)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_CHANGE_SERVER_USER_LOGIN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public bool SendLogOut()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_LOGOUT, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeEnd();
            return (_mySokcet.sendcmd());
        }

        public void RequestFromToAllChips(int _arg1, int _arg2, int _arg3, int _arg4, string _arg5)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_FROMTOALLCHIPS, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeByte(_arg4);
            _mySokcet.writeString(_arg5);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestChipin(int _arg1, Int64 _arg2, string _arg3)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_CHIPIN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeByte(_arg1);  // GameConfig.CHIPIN_CALL or GameConfig.CHIPIN_CHECK
            _mySokcet.writeInt64(_arg2); // Money
            _mySokcet.writeString(_arg3); // userkey
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestShowDealPreflopCard(int _arg1, int _arg2)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_SHOWDEALPREFLOPCARD, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void ContinueBuying(int _arg1, Int64 _arg2, int _arg3)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_CONTINUE, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt64(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestLotteryBuy(int _arg1)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_LOTTERYBUY, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void startBroken()
        {
            //_clientSocket.startBroken();
        }

        public void SendClientEchoConnection()
        {
            _mySokcet.writeBegin(CLIENT_ECHO_CONN, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestUserVote(int _arg1, int _arg2)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_KICKUSER_REQUEST, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestTableInfo()
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_TABLEINFO_REQUEST, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void SendChatInfo(string _arg1, string _arg2="")
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_CHAT, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeString(_arg1);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void RequestAddFriend(int _arg1, int _arg2, int _arg3, int _arg4, string _arg5)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_ADDFRIEND, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeByte(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeInt(_arg4);
            _mySokcet.writeString(_arg5);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void connect(string _arg1, int _arg2)
        {
            _mySokcet.connect(_arg1, _arg2);
            //trace(((("主机:" + _arg1) + " 端口:") + _arg2));
        }

        public void RequestFromToChips(int _arg1, int _arg2, int _arg3, int _arg4, int _arg5, string _arg6, int _arg7 = 0, Int64 _arg8 = -1, String _arg9 = "")
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_FROMTOCHIPS, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeByte(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeInt64(_arg4);
            _mySokcet.writeByte(_arg5);
            _mySokcet.writeString(_arg6);
            _mySokcet.writeInt(_arg7);
            _mySokcet.writeInt64(_arg8);
            _mySokcet.writeString(_arg9);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void SendSitRequset(int _arg1, Int64 _arg2, int _arg3 = 0)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_SIT_REQUEST, SERVER_PACKET_VER, SERVER_SUBPACKET_VER2);
            _mySokcet.writeByte(_arg1);
            _mySokcet.writeInt64(_arg2);
            _mySokcet.writeInt(_arg3);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }

        public void close()
        {
            _mySokcet.close();
            //trace("连接关闭");
        }

        public void RequestUpdateInfo(int _arg1, int _arg2, string _arg3)
        {
            _mySokcet.writeBegin(CLIENT_COMMAND_USER_NOTICEALL, SERVER_PACKET_VER, SERVER_SUBPACKET_VER);
            _mySokcet.writeInt(_arg1);
            _mySokcet.writeInt(_arg2);
            _mySokcet.writeString(_arg3);
            _mySokcet.writeEnd();
            _mySokcet.sendcmd();
        }
    }
}

